import Vue from 'vue'
import axios from '../utils/axios'
import ViewUI from 'view-design';
import { BASE_URL } from '../config/index'

Vue.use(ViewUI);

const IS_CHN = new RegExp('^[\u4e00-\u9fa5]{0,}$')
const IS_NUM = new RegExp('^[0-9]*$')
const IS_ENG = new RegExp('^[A-Za-z]*$')
const IS_ENG_NUM = new RegExp("^[A-Za-z0-9]{4,10}$")


export default Vue.mixin({
    data() {
        return {

        }
    },
    filters: {
        fmtOrder2ABC(val) {
            return 'ABCDEFGHIJKLMNOPQRST' [val]
        },
        fmtOrder2CN(val) {
            return '零一二三四五六七八九十' [val]
        }
    },
    methods: {
        IsCHN(val) {
            return IS_CHN.test(val)
        },
        IsENG(val) {
            return IS_ENG.test(val)
        },
        IsNUM(val) {
            return IS_NUM.test(val)
        },
        IsAccountorPWD(val) {
            return IS_ENG_NUM.test(val)
        },
        async $get(url, params) {
            let { data } = await axios.get(BASE_URL + url, { params })
            return data
        },
        async $post(url, params) {
            let { data } = await axios.post(BASE_URL + url, params)
            return data
        },
        async $getP(url, params) {
            let { data } = await axios.get(url, { params })
            return data
        },
        async $postP(url, params) {
            let { data } = await axios.post(url, params)
            return data
        },
        $find(arr, key, val) {
            return arr.find(r => r[key] == val)
        },
        // 封装message方法
        $ms(msg) {
            this.$Message.success(msg)
        },
        $mw(msg) {
            this.$Message.warning(msg)
        },
        $me(msg) {
            this.$Message.error(msg)
        }
    },
})